package edu.mis.modules.customer;

import java.util.List;
import java.util.Map;

import com.jfinal.core.ActionKey;
import com.jfinal.core.Controller;

import edu.mis.model.Customer;

public class CustomerController extends Controller{
	//鍒涘缓涓�涓猄ervice
	private CustomerService service = new CustomerService();
	
	
	//榛樿鎵цindex鏂规硶
	public void index(){
		render("customer.html");
	}
	public void list(){
		setAttr("data", service.getAllCustomer());
		renderJson();  
	}
	
	public void edit() {
		setAttr("user", service.findCustomerById(getParaToInt("id")));  //此处customer应与表单中${(user.name)!}等中的user保持一致。
	}
	
	public void updateAge(){
		int id=this.getParaToInt("id");   //使用getPara获取表单值，与getModel方法获得表单值不同，name不能使用对象名.属性名，如user.password，而直接使用属性名，如password
		int newAge = this.getParaToInt("age");
		if(service.updateAge(id, newAge)){
			setAttr("result", true);
			setAttr("msg", "修改密码成功!");
		}else{
			setAttr("result", false);
		}
		renderJson();
	}
}
